<template>
  <div>
    <h1>我是注册页面电影网站</h1>
    mobile手机 <input type="text" v-model="mobile" /> <br />
    用户密码 <input type="text" v-model="password" /> <br />

    <button @click="handleRegister">点击注册账号</button>
  </div>
</template>

<script>
import axios from "axios";
export default {
  props: [],
  components: {},
  data() {
    return {
      mobile: "",
      password: "",
       
    };
  },

  methods: {
    handleRegister() {
      console.log("进来 register");
      //   手机号正则
      var myphonereg = /^[1][3,5,7,8][0-9]{9}$/;
      //   手机号的正则
      if (!myphonereg.test(this.mobile)) {
        this.$message({
          message: "手机号填写不正确",
          type: "warning",
        });

        return;
      }

      // 密码正则校验
      var myreg2 = /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{8,}$/;

      if (!myreg2.test(this.password)) {
        this.$message({
          message: "密码填写不正确",
          type: "warning",
        });
        return;
      }
        
      // 以上两个都成功就可以向后端发送axios请求
      axios
        .post("http://127.0.0.1:3000/zhuce", {
          mobile: this.mobile,
          password: this.password,
        })
        .then((data) => {
          console.log("注册then", data);
          if (data.data.code == "200") {
            this.$message({
              message: "成功注册 2s后准备跳转",
              type: "success",
            });
            setTimeout(()=>{
                this.$router.push('/login')
            },2000)
          
          }else {
               this.$message({
              message: " 注册失败",
              type: "warning",
            });
          }
        });
    },
  },

  computed: {},

  watch: {},

  filters: {},

  beforeCreate() {},

  created() {},

  beforeMount() {},

  mounted() {},

  beforeUpdate() {},

  updated() {},

  beforeDestroy() {},

  destroyed() {},
};
</script>


<style  lang='scss'>
</style>
